package cn.itcast.listener;

import com.alibaba.fastjson.JSON;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import utils.MailUtil;

import java.util.Map;

public class EmailListener implements MessageListener {

 public void onMessage(Message message) {
  byte[] body = message.getBody(); //数据
  //将body转化为json，json还原成map集合
  Map map = JSON.parseObject(body, Map.class);
  //调用工具类发送邮件
  String to = (String)map.get("to");
  String subject = (String)map.get("subject");
  String content = (String)map.get("content");
  System.out.println(to);
  System.out.println(subject);
  System.out.println(content);
  try {
   MailUtil.sendMsg(to, subject, content);
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}
